package football.haha.com.footballtv.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import football.haha.com.footballtv.FootballApplication;
import football.haha.com.footballtv.R;
import football.haha.com.footballtv.bean.BeanIndexFootball;
import football.haha.com.footballtv.utils.ActivityUtils;
import football.haha.com.footballtv.utils.ImageToos;
import football.haha.com.footballtv.view.SmoothVorizontalScrollView;

/**
 * Created by haha on 2017/10/6.
 */

public class LeagueMoreActivity extends BaseActivity {

    @Bind(R.id.fl_football_league)
    FrameLayout flFootballLeague;
    @Bind(R.id.fl_fight_league)
    FrameLayout flFightLeague;
    @Bind(R.id.ll_main)
    LinearLayout llMain;
    @Bind(R.id.fl_content)
    LinearLayout flContent;
    @Bind(R.id.svs_content)
    SmoothVorizontalScrollView svsContent;


    private ArrayList<BeanIndexFootball.LeagueMatchListBean.ListBean> leagueList = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_league_more);
        ButterKnife.bind(this);

        leagueList = getIntent().getParcelableArrayListExtra("leagueList");
        addFootballLeague();
//        addFightLeague();

        svsContent.setFadingEdge((int)getResources().getDimension(R.dimen.px270));

        createBorderView(llMain);


    }

    private void addFootballLeague() {
        int allHeight = 0;
        for (int i = 0; i < leagueList.size(); i++) {
            View itemFootball = View.inflate(this, R.layout.item_league, null);

            ImageView ivIcon = (ImageView) itemFootball.findViewById(R.id.iv_icon);
            BeanIndexFootball.LeagueMatchListBean.ListBean listBean = leagueList.get(i);
            ImageToos.setImageWithUrl(listBean.getLogoUrl(), ivIcon, FootballApplication.getOptions(R.drawable.default_video));

            itemFootball.setOnClickListener(this);
            itemFootball.setOnFocusChangeListener(this);
            itemFootball.setId(i+2000);
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams((int) getResources().getDimension(R.dimen.px280),
                    (int) getResources().getDimension(R.dimen.px170));

            int topMargin = (int) getResources().getDimension(R.dimen.px20) + i / 6 * (int) getResources().getDimension(R.dimen.px190);
            int leftMargin = (int) getResources().getDimension(R.dimen.px95) + i % 6 * (int) getResources().getDimension(R.dimen.px295);

            params.topMargin = topMargin;
            params.leftMargin = leftMargin;

            flFootballLeague.addView(itemFootball, params);
            allHeight = topMargin + params.height + (int) getResources().getDimension(R.dimen.px70);
        }

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, allHeight);
        flFootballLeague.setLayoutParams(params);

    }

    private void addFightLeague() {
        int allHeight = 0;
        for (int i = 0; i < 10; i++) {
            View itemFight = View.inflate(this, R.layout.item_league, null);
            itemFight.setOnClickListener(this);
            itemFight.setId(i+2000);
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams((int) getResources().getDimension(R.dimen.px280),
                    (int) getResources().getDimension(R.dimen.px170));

            int topMargin = (int) getResources().getDimension(R.dimen.px20) + i / 6 * (int) getResources().getDimension(R.dimen.px190);
            int leftMargin = (int) getResources().getDimension(R.dimen.px95) + i % 6 * (int) getResources().getDimension(R.dimen.px295);

            params.topMargin = topMargin;
            params.leftMargin = leftMargin;

            flFightLeague.addView(itemFight, params);
            allHeight = topMargin + params.height + (int) getResources().getDimension(R.dimen.px70);
        }

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, allHeight);
        flFightLeague.setLayoutParams(params);

    }


    @Override
    public void onClick(View view) {
        super.onClick(view);

        BeanIndexFootball.LeagueMatchListBean.ListBean bean = leagueList.get(view.getId()-2000);
        Intent intent = new Intent(LeagueMoreActivity.this, LeagueHomeDataActivity.class);
        intent.putExtra("League", bean);
        ActivityUtils.gotoActivityWithIntent(this, intent);
    }
}
